unit Class_Crew;

interface
uses
  Classes,SysUtils,ADODB,DBEngine;

type
  TCrew=class(TDBEngine)
  public
    UnitLink:string;
    DeptLink:string;
    CrewIdex:Integer;
    CrewName:string;
    CrewProf:string;
    CrewWork:string;
    CrewStat:Integer;
    CrewMail:string;
    CrewCall:string;
    CrewMemo:string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
    class function ReadDS(AADODS:TADODataSet):TDBEngine;override;
  end;

implementation

{ TCrew }

function TCrew.GetStrDelete: string;
begin

end;

function TCrew.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_CREW '
        + '    (UNIT_LINK, DEPT_LINK, CREW_IDEX, CREW_NAME, CREW_PROF, CREW_STAT, '
        + '    CREW_WORK, CREW_CALL, CREW_MAIL, CREW_MEMO)'
        + '    VALUES(:UNIT_LINK, :DEPT_LINK, :CREW_IDEX, :CREW_NAME, :CREW_PROF, :CREW_STAT, '
        + '    :CREW_WORK, :CREW_CALL, :CREW_MAIL, :CREW_MEMO)';
end;

function TCrew.GetStrUpdate: string;
begin
  Result:='UPDATE TBL_CREW SET'
        + '    DEPT_LINK = :DEPT_LINK,'
        + '    CREW_NAME = :CREW_NAME,'
        + '    CREW_PROF = :CREW_PROF,'
        + '    CREW_STAT = :CREW_STAT,'
        + '    CREW_WORK = :CREW_WORK,'
        + '    CREW_CALL = :CREW_CALL,'
        + '    CREW_MAIL = :CREW_MAIL,'
        + '    CREW_MEMO = :CREW_MEMO'
        + '    WHERER  UNIT_LINK=:UNIT_LINK'
        + '    AND     CREW_IDEX = :CREW_IDEX';
end;

class function TCrew.ReadDS(AADODS: TADODataSet): TDBEngine;
begin
  Result:=TCrew.Create;
  with TCrew(Result) do
  begin
    UNITLINK := Trim(AADODS.FieldByName('UNIT_LINK').AsString);
    DEPTLINK := Trim(AADODS.FieldByName('DEPT_LINK').AsString);
    CREWIDEX := AADODS.FieldByName('CREW_IDEX').AsInteger;
    CREWNAME := Trim(AADODS.FieldByName('CREW_NAME').AsString);
    CREWPROF := Trim(AADODS.FieldByName('CREW_PROF').AsString);
    CREWSTAT := AADODS.FieldByName('CREW_STAT').AsInteger;
    CREWWORK := Trim(AADODS.FieldByName('CREW_WORK').AsString);
    CREWCALL := Trim(AADODS.FieldByName('CREW_CALL').AsString);
    CREWMAIL := Trim(AADODS.FieldByName('CREW_MAIL').AsString);
    CREWMEMO := Trim(AADODS.FieldByName('CREW_MEMO').AsString);
  end;  
end;

procedure TCrew.SetParameters;
begin
  inherited;
  with FADOCmd.Parameters do
  begin
    case FOpType of
      otAdd,otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('DEPT_LINK').Value := DEPTLINK;
        ParamByName('CREW_IDEX').Value := CREWIDEX;
        ParamByName('CREW_NAME').Value := CREWNAME;
        ParamByName('CREW_PROF').Value := CREWPROF;
        ParamByName('CREW_STAT').Value := CREWSTAT;
        ParamByName('CREW_WORK').Value := CREWWORK;
        ParamByName('CREW_CALL').Value := CREWCALL;
        ParamByName('CREW_MAIL').Value := CREWMAIL;
        ParamByName('CREW_MEMO').Value := CREWMEMO;
      end;
      otDel:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('CREW_IDEX').Value := CREWIDEX;
      end;  
    end;

  end;  
end;

end.
